//符合AMD规范的写在前面
define(['zepto','gmu','underscore','handlebars','app/loader','app/toast','app/submitData'],function ($,gmu,_,Handlebars,loader,toast,submitData) {

    function homePage() {
        this.runTimes=0;
        this.leftTime=$("#reverseBox").data("time");
    }

    homePage.prototype._init = function () {
        var _this = this;
        var source=$("#entryTemplate").html();
        var tempGo=Handlebars.compile(source);
        var context ={
            people: [
                {firstName: "Yehuda", lastName: "Katz"},
                {firstName: "Carl", lastName: "Lerche"},
                {firstName: "Alan", lastName: "Johnson"}
            ]
        };

        Handlebars.registerHelper('list',function(items,options){
            var out="<ul>";
            for(var i= 0,len=items.length;i<len;i++){
                out=out+"<li>"+options.fn(items[i])+"</li>";
            }
            return out+="</ul>";
        });

        var html=tempGo(context);
        //$("#renderBox").html(html);

        this.timeReverse();
        setInterval(function(){
            _this.timeReverse();
        },1000);
    };

    homePage.prototype.timeReverse=function(){
        var _this=this;
        var nMS=_this.leftTime*1000-_this.runTimes*1000;
        var nD=Math.floor(nMS/(1000*3600)/24);
        var nH=Math.floor(nMS/(1000*60*60))%24;
        var nM=Math.floor(nMS/(1000*60)) % 60;
        var nS=Math.floor(nMS/1000) % 60;

        nMS=nMS<10?"0"+nMS:nMS;
        nD=nD<10?"0"+nD:nD;
        nH=nH<10?"0"+nH:nH;
        nM=nM<10?"0"+nM:nM;
        nS=nS<10?"0"+nS:nS;

        $("#RemainD").html(nD);
        $("#RemainH").html(nH);
        $("#RemainM").html(nM);
        $("#RemainS").html(nS);

        if(nMS>5*59*1000&&nMS<=5*60*1000)
        {
            alert("还有最后五分钟！");
        }
        _this.runTimes++;
    };

    homePage.prototype.render = function () {
        this._init();
    };

    return homePage;
});
